/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.Dashboards;

import entity.establishment.OutletFood;
import entity.establishment.Stakeholder;
import entity.establishment.StakeholderFood;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.component.submenu.Submenu;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;
import session.TX.OutletSBRemote;
import session.TX.StakeholderAccountsSBRemote;

/**
 *
 * @author Randall Chia
 */
@ManagedBean(name = "outletManagerDashboardMB")
@ViewScoped
public class OutletManagerDashboardMB {

    private MenuModel outletManagerModel;
    private String stakeholderName;
    private Long stakeholderId;
    private String accountType;
    private Long accountId;
    
    @EJB
    private StakeholderAccountsSBRemote stakeholderManager;
    @EJB
    private OutletSBRemote outletBean;


    public OutletManagerDashboardMB() {
    }

    public void initView(PhaseEvent event) {
        System.out.println("outlet manager dashboard init...");
        try {
            accountType = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("accountType");
            if (accountType != null) {
                accountId = Long.valueOf(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("accountId").toString());

                if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholderId") != null) {
                    stakeholderId = Long.valueOf(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholderId").toString());
                    stakeholderName = (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholderName").toString());
                }
                //getAccountRoles();
                generateDashboard();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//initView

    public void generateDashboard() {
        System.out.println("account type   >>>> " + accountType);
        outletManagerModel = new DefaultMenuModel();
        Submenu submenu = new Submenu();
        MenuItem item = new MenuItem();

        if (accountType.compareTo("admin") == 0) {
            System.out.println(">>> DashboardMB: Generating Dashboard for TCube Admin");


        }

        //---------------------------------------------------------------------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------------------------------------------------------------------

        
        if (accountType.compareTo("representative") == 0) {

                //Menu for outlet manager --------------------------------------------------------------------------------------------------------------
                
                //Check if there is an outlet ID in session. If so, then the outletManagerModel must be populated
                Long outletID;
                try{
                    outletID = (Long) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("outletId");
                    if (outletID != null) {
                        
                        System.out.println(">>> DashboardMB: Generating Dashboard for Outlet Management");

                        
                        //Submenu: Item redemption
                        submenu = new Submenu();
                        submenu.setLabel("Item Redemption");
                        
                        item = new MenuItem();
                        item.setValue("Redeem Customer Purchase");
                        item.setUrl("/stakeholder/OutletManager/purchaseredemption.xhtml");
                        submenu.getChildren().add(item);
                        
                        item = new MenuItem();
                        item.setValue("Redeem Deals or Rewards");
                        item.setUrl("/stakeholder/OutletManager/dealredemption.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);
                        
                        //Submenu: Dish Management
                        submenu = new Submenu();
                        submenu.setLabel("Food Items");
                        
                        item = new MenuItem();
                        item.setValue("Manage Menu");
                        item.setUrl("/stakeholder/OutletManager/fooditemmanagement.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);
                        
                        
                        //submenu: Manage Reservation Info
                        submenu = new Submenu();
                        submenu.setLabel("Manage Reservation Info");

                        item = new MenuItem();
                        item.setValue("General Information");
                        item.setUrl("/stakeholder/OutletManager/general.xhtml");
                        submenu.getChildren().add(item);

//                        item = new MenuItem();
//                        item.setValue("Layout Management");
//                        item.setUrl("/stakeholder/OutletManager/layout.xhtml");
//                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);

                        //Submenu: Area Management
                        submenu = new Submenu();
                        submenu.setLabel("Area Management");

                        item = new MenuItem();
                        item.setValue("Manage Areas");
                        item.setUrl("/stakeholder/OutletManager/areamanagement.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);

                        //Submenu: Timeslot management
                        submenu = new Submenu();
                        submenu.setLabel("Timeslot Management");

                        item = new MenuItem();
                        item.setValue("Manage Reservation Timeslots");
                        item.setUrl("/stakeholder/OutletManager/managetimeslotbyarea.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);

                        //Submenu: Manage Customer Reservations
                        submenu = new Submenu();
                        submenu.setLabel("Manage Customer Reservations");

                        item = new MenuItem();
                        item.setValue("Update Reservation Status (For Manual Confirmation)");
                        item.setUrl("/stakeholder/OutletManager/updatereservationstatus.xhtml");
                        submenu.getChildren().add(item);

                        item = new MenuItem();
                        item.setValue("Record Customer Show-up");
                        item.setUrl("/stakeholder/OutletManager/recordshowup.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);

                        //TTA submenu
                        submenu = new Submenu();
                        submenu.setLabel("Analytics");

                        item = new MenuItem();
                        item.setValue("Outlet Transaction Analytics");
                        item.setUrl("/stakeholder/OutletManager/TTA/main.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);
                        
                        //Summary submenu
                        submenu = new Submenu();
                        submenu.setLabel("Reports");

                        item = new MenuItem();
                        item.setValue("Generate Summary");
                        item.setUrl("/stakeholder/OutletManager/generatesummary.xhtml");
                        submenu.getChildren().add(item);

                        outletManagerModel.addSubmenu(submenu);

                    }
                    
                }catch(NullPointerException e){
                }//end catch
                

                //End Menu for outlet manager --------------------------------------------------------------------------------------------------------------
                

            //---------------------------------------------------------------------------------------------------------------------------------------------------------
            //---------------------------------------------------------------------------------------------------------------------------------------------------------
        }

    }

    public MenuModel getOutletManagerModel() {
        return outletManagerModel;
    }

    public void setOutletManagerModel(MenuModel outletManagerModel) {
        this.outletManagerModel = outletManagerModel;
    }
}